package com.lwg.practice.LinkList;

import java.util.HashSet;
import java.util.List;

/**
 * @author: liwg
 * @Date: 2021/9/14 0014 12:32
 * @Description:
 */
public class demo2 {
    /*public ListNode deleteDuplicates(ListNode head) {
        //移除重复的节点数字
       if (head==null||head.next==null){
         return head;
      }
      head.next=deleteDuplicates(head.next);
      return head.val==head.next.val?head.next:head;

    }*/
    //反转链表即将给定元素的后的节点依次插入到给定元素前
    /*public ListNode reverseBetween(ListNode head, int left, int right) {
        ListNode dump = new ListNode(0);
        dump.next = head;
        ListNode p = dump;
        ListNode g = dump.next;
        for (int i = 0; i < left - 1; i++) {
            p = p.next;
            g = g.next;
        }
        for (int j = 0; j < right-left; j++) {
            ListNode cur=g.next;
            g.next=g.next.next;
            cur.next=p.next;
            p.next=cur;
            p=p.next;
        }
        return dump.next;
    }*/


    //得到两个链表第一个相同的节点
    //1. 利用HashSet保存链表A的节点  然后依次比较改Set中是否包含B中的节点。有就返回，没有返回null
    /*HashSet set=new HashSet();
        while(headA!=null){
        set.add(headA);
        headA=headA.next;
    }
        while(headB!=null){
        if(set.contains(headB)){
            return headB;
        }
        headB=headB.next;
    }
        return null;*/

    //2.让A和B 都走一遍自己的链表和对方的俩链表，当相遇了即有共同的节点
   /* ListNode node1=headA;
    ListNode node2=headB;
       while(node1!=node2){
        node1=node1==null?headB:node1.next;
        node2=node2==null?headA:node2.next;
    }
       return node1;
*/
}

class ListNode {
    int val;
    ListNode next;

    ListNode() {
    }

    ListNode(int val) {
        this.val = val;
    }

    ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }
}